<?php
require_once '../Config.php';
$con = mysql_connect ( host, username, password );
if (! $con) {
	die ( 'Could not connect: ' . mysql_error () );
}
mysql_select_db ( db, $con );
$arr = array();
$deviceid = $_REQUEST['deviceid'];
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];


$sql = "set names utf8";
mysql_query($sql);
$sql = "select * from j_tab_user where deviceid='".$deviceid."'";
$result = mysql_query($sql);
$lines = mysql_numrows($result);
if ($lines > 0) {
	if(empty($result)){
		$arr['success'] = 0;
		$arr['error'] = "设备未注册，请联系管理员！";
		$json = json_encode($arr);
		echo $json;
	}else{
		if($row=mysql_fetch_array($result)){
			$user = $row['username'];
			$pwd = $row['password'];
			if($username != $user){
				$arr['success'] = 0;
				$arr['error'] = "用户名错误！";
			}else if($pwd != $password){
				$arr['success'] = 0;
				$arr['error'] = "密码错误！";
			}else{
				$arr['success'] = 1;
				$arr['error'] = "";
					
				$arr['id'] = $row['id'];
				$arr['username'] = $row['username'];
				$arr['phone'] = $row['phone'];
				$arr['time'] = $row['time'];
			}
			$json = json_encode($arr);
			echo $json;
		}else{
			$arr['success'] = 0;
			$arr['error'] = "设备未注册，请联系管理员！";
			$json = json_encode($arr);
			echo $json;
		}
		
	}	
}else{
	$arr['success'] = 0;
	$arr['error'] = "设备未注册，请联系管理员！";
	$json = json_encode($arr);
	echo $json;
}

?>